//
//  LFBReadPreviousCell.m
//  ONE
//
//  Created by dllo on 16/6/10.
//  Copyright © 2016年 GroupNine. All rights reserved.
//

#import "LFBReadPreviousCell.h"
#import "LFBReadShortModel.h"
#import "LFBReadSerialModel.h"
#import "LFBReadQuestionModel.h"

NSString *const kLFBReadPreviousCellID = @"LFBReadPreviousCellID";

@interface LFBReadPreviousCell ()

/** 文章标题 */
@property (nonatomic, strong) UILabel *titleLabel;

/** 文章类型 */
@property (nonatomic, strong) UIImageView *readTypeView;

/** 作者label */
@property (nonatomic, strong) UILabel *authorLabel;

/** 内容label */
@property (nonatomic, strong) UILabel *contentLabel;

@end

@implementation LFBReadPreviousCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self createPreviousCell];
    }
    return self;
}

- (void)createPreviousCell
{
    if (_titleLabel) {
        return;
    }
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    _titleLabel = [UILabel new];
    _titleLabel.backgroundColor = [UIColor whiteColor];
    _titleLabel.font = BoldFontWithSize(18);
    _titleLabel.textColor = LYLDarkBlackTextColor;
    _titleLabel.numberOfLines = 0;
    [self.contentView addSubview:_titleLabel];
    [_titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(16);
        make.left.equalTo(self.contentView).offset(10);
    }];
    
    _readTypeView = [UIImageView new];
    _readTypeView.contentMode = UIViewContentModeScaleAspectFit;
    _readTypeView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_readTypeView];
    [_titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.size.sizeOffset(CGSizeMake(41, 19));
        make.top.equalTo(_titleLabel);
        make.left.greaterThanOrEqualTo(_titleLabel.right).offset(10);
        make.right.equalTo(self.contentView).offset(-10);
    }];
    
    _authorLabel = [UILabel new];
    _authorLabel.backgroundColor = [UIColor whiteColor];
    _authorLabel.font = FontWithSize(13);
    _authorLabel.textColor = LYLLightBlackTextColor;
    [self.contentView addSubview:_authorLabel];
    [_authorLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.bottom).offset(10);
        make.left.equalTo(_titleLabel);
        make.right.equalTo(_readTypeView);
    }];
    
    _contentLabel = [UILabel new];
    _contentLabel.backgroundColor = [UIColor whiteColor];
    _contentLabel.font = FontWithSize(13);
    _contentLabel.textColor = LYLLightBlackTextColor;
    _contentLabel.numberOfLines = 0;
    [self.contentView addSubview:_contentLabel];
    [_contentLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_authorLabel.bottom).offset(10);
        make.left.right.equalTo(_authorLabel);
        make.bottom.equalTo(self.contentView).offset(-24);
    }];
}

#pragma mark --设置往期列表视图cell
- (void)configureViewWithReadModel:(BaseModel *)model type:(LYLReadType)type atIndexPath:(NSIndexPath *)indexPath
{
    switch (type) {
        case LYLReadTypeShort:
        {
            LFBReadShortModel *shortModel = (LFBReadShortModel *)model;
            _titleLabel.text = shortModel.hp_title;
            _authorLabel.text = ((LYLAuthorItemModel *)[shortModel.author firstObject]).user_name;
            _contentLabel.text = shortModel.guide_word;
            _readTypeView.image = [UIImage imageNamed:@"icon_read"];
            break;
        }
        case LYLReadTypeSerial:
        {
            LFBReadSerialModel *serialModel = (LFBReadSerialModel *)model;
            _titleLabel.text = [NSString stringWithFormat:@"%@( %@ )", serialModel.title, serialModel.number];
            _authorLabel.text = serialModel.model.user_name;
            _contentLabel.text = serialModel.excerpt;
            _readTypeView.image = [UIImage imageNamed:@"icon_serial"];
            break;
        }
        case LYLReadTypeQuestion:
        {
            LFBReadQuestionModel *questionModel = (LFBReadQuestionModel *)model;
            _titleLabel.text = questionModel.question_title;
            _authorLabel.text = @"";
            _contentLabel.text = questionModel.answer_title;
            _readTypeView.image = [UIImage imageNamed:@"icon_question"];
            break;
        }
        default:
            break;
    }
}

@end
